<template>
	<view class="warp">
		<view class="home_top"></view>
		<view :style="{
		color: '#FFFFFF',
		width: '100%',
		display: 'flex',
		'justify-content': 'center',
		'position': 'fixed',
		'border-radius': '0 0 80rpx 80rpx',
		top: statusBarHeight,
	}">登录</view>
		<view class="center_box">
			<button class="box_item box-s1" @click="choose('1')">
				<image src="../../static/yh.png" class="suolue"></image>
				<view class="type" style="color: #FEC860;">我是用户</view>
				<view class="iconfont right" style="color: #FEC860 ;">&#xe60f;</view>
			</button>
			<button class="box_item box-s1" @click="choose('2')">
				<image src="../../static/sf.png" class="suolue"></image>
				<view class="type" style="color: #5490FE;">我是师傅</view>
				<view class="iconfont right" style="color: #5490FE;">&#xe60f;</view>
			</button>
		</view>
		<view class="footer">
			<text class="red">*温馨提示:</text> 如果选择身份错误,请联系客服!
		</view>
	</view>
</template>

<script>
	import {
		chooseType
	} from '../../api/api.js'
	export default {
		data() {
			return {
				statusBarHeight: "100rpx",
				uid: "",
			}
		},
		created() {
			this.statusBarHeight = uni.getStorageSync('statusBarHeight')
			let uid = uni.getStorageSync('uid')
			if (uid) {
				this.uid = uid
			}
		},
		methods: {
			getUserInfo() {
				console.log('获取用户信息')
			},
			choose(e) {
				console.log('e', e)
				let _this = this
				let usert = ''
				e==1? usert="用户":usert="师傅"
				uni.showModal({
					title:'提示!',
					content:`您当前选择${usert},身份选择后不可更改,请慎重选择!`,
					showCancel:true,
					cancelText:'重新选择',
					success: (res) => {
						if(res.confirm){
							uni.getUserProfile({
								desc: '用于完善资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
								success: (res) => {
							
									uni.setStorageSync('current', 0)
									_this.userInfo = wx.getStorageSync('userInfo', res.userInfo)
									wx.setStorageSync('hasUserInfo', true);
									let data = {
							
										type: e,
										avatarUrl: res.userInfo.avatarUrl,
										city: res.userInfo.city,
										country: res.userInfo.country,
										province: res.userInfo.province,
										gender: res.userInfo.gender,
										language: res.userInfo.language,
										nickName: res.userInfo.nickName,
									}
									chooseType(data).then(res => {
										uni.setStorageSync('userInfo', res.data);
										if (e == 1) {
											uni.setStorageSync('userType', 1)
											uni.redirectTo({
												url: "/pages/index/index"
											})
										} else {
											uni.setStorageSync('userType', 2)
											uni.redirectTo({
												url: "/pages/index/index"
											})
										}
									})
							
							
								},
								fail: (err) => {
									console.log('err', err);
								}
							})
						}else{
							
						}
					}
				})
			


				console.log(uni.getStorageSync('userType'), uni.getStorageSync('current'))
			}
		}
	}
</script>

<style scoped lang="less">
	.warp {
		background-color: #FFFFFF;
	}

	.center_box {
		display: block;
		margin-top: -150rpx;
		text-align: center;
		// background-color: blue;
		// width: 100%;
		padding: 0 50rpx;

		.box_item {
			width: 100%;
			position: relative;
			background-color: #FFFFFF;
			border-radius: 10rpx;
			height: 250rpx;
			margin-top: 50rpx;

			image {
				position: absolute;
				top: 45rpx;
				left: 20rpx;
			}

			.type {
				font-size: 36rpx;
				font-weight: 550;
				position: absolute;
				top: 90rpx;
				left: 200rpx;
				color: #333333;
			}

			.right {
				position: absolute;
				right: 30rpx;
				top: 90rpx;
				color: #999999;
			}
		}
	}

	.footer {
		text-align: center;
		margin-top: 50rpx;
	}
</style>
